/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.webserver.inMemory;

import mb.config.Constants;
import mb.config.ConstantsMsg;
import static mb.webserver.inMemory.BaseProcess.nError;
import static mb.webserver.inMemory.BaseProcess.nStatus;
import net.sf.json.JSONObject;
import org.json.simple.JSONValue;

/**
 *
 * @author thanh.nguyenchi
 */
public class MBServerConfigProcess extends BaseProcess{
    
    String server;
    String lang;
    String version;

    public MBServerConfigProcess(String serverLink,String version,String lang){
        this.server = serverLink;
        this.version = version;
        this.lang = lang;
        process();
    }
    
    @Override
    public void process(){
        // xu ly logic
        if ((this.server != null) && (this.server.length() > Constants.INT_MIN_SERVER_CONFIG)){
            status = ConstantsMsg.INT_SUCESSFUL_CODE;
            error = "";
        }
        else{
            status = ConstantsMsg.INT_SERVER_LINK_CODE;
            error = ConstantsMsg.getErrMsg(status,lang);
        }
        return;
    }
    
    @Override
    public String toJson(){
        JSONObject obj = new JSONObject();
        obj.put(nStatus,new Long(status));
        obj.put(nError,this.error);
        obj.put(nServer,this.server);        
        obj.put(nLang,this.lang);
        obj.put(nVersion,this.version);
        return JSONValue.toJSONString(obj);
    }
       
}
